home *** CD-ROM | disk | FTP | other *** search
- '
- 'Class description:
- '
- !short:Stack class structure
- Class Stack:
- ~~~~~~~~~~~~~
- Stack is defined as an object.
-
-
- Common use:
- ~~~~~~~~~~~~~~~~~
- LOCAL OBJECT Stack OF Stack
- Stack:Push(...) //can be used repeatedly
- ...
- x:=Stack:Pop() //can be repeated
-
- Source code of class Stack is in C_Stack.prg
-
- !seealso: c_menu.ngo:Menu c_color.ngo:Color ob_class.ngo:"Class hierarchy"
-
- !short:~~~~~~~~~~~~~~~~~~~~~~~
- !short:create class Stack
- !short: export:
- !short: var Data //{}
- ^BStack:Data^N: private: array
- Array which data is filled by Push(val) method and retrieved by
- Pop() method.
-
- !short: method New=StackNew //o:New() --> self
- ^BStack:New()^N: public: return self
- Object is filled with default values.
-
- !short: method Init=StackInit //o:Init() --> true
- ^BStack:Init()^N: public: return true
- The stack is initialised, i.e. the instvar variable is set to {}
- (empty array).
-
- !short: method Push=StackPush //o:Push(val) --> xVal
- ^BStack:Push(xVal)^N: public: return xVal
- The value xVal is stored on top of the stack.
-
- !short: method Pop=StackPop //o:Pop() --> xVal
- ^BStack:Pop()^N: public: return xVal
- The last stored value is retrieved as result and stack is lowered by one.
-
- !short: method Top=StackTop //o:Top() --> xVal
- ^BStack:Top()^N: public: return xVal
- The last stored value is returned, no stack size change.
-
- !short: method IsEmpty=StackIsEmpty //o:IsEmpty() --> true/false
- ^BStack:IsEmpty()^N: public: return true/false
- If empty true is returned, else false is returned.
-
- !short: method Done=StackDone //o:Done() --> true
- ^BStack:Done()^N: public: return true
- Nothing to do because the memory becomes free when the object is destroyed.
- When the object of class Stack is destroyed, its instvar variable
- Stack:data is also destroyed.
-
- !short: endclass
-
-